package practise.mulitThreads.ConcurrentInPractice.CustomerizedCounter;

/**
 * Created by richard on 6/14/14.
 */
public class Counter {
    SimulatedCAS simulatedCAS = new SimulatedCAS();
    public int increatmentAndGet(){
        while(!simulatedCAS.compareAndSet(simulatedCAS.get(),simulatedCAS.get()+1));
        return simulatedCAS.get();
    }

    public int addAndGet(){
        int count =0;
        do{
            count = simulatedCAS.get();
        }
        while( count!=simulatedCAS.compareAndSwap(simulatedCAS.get(), simulatedCAS.get() + 1));
        return count+1;
    }
}
